package com.example.park

import com.example.base.mvi.BaseViewModel
import com.example.base.mvi.HttpType
import com.example.base.net.ApiService
import dagger.hilt.android.lifecycle.HiltViewModel
import javax.inject.Inject
@HiltViewModel
class ParkViewModel @Inject constructor(val apiService: ApiService):BaseViewModel<ParkIntent>() {
    override fun handleIntent(it: ParkIntent) {
        when(it){
            is ParkIntent.parkType -> {
                //pageRequest({ParkDataSource(apiService,it.spaceType)},HttpType.DEFAULT)
                httpRequest(apiService.parkType(it.spaceType),HttpType.DEFAULT)
            }
            is ParkIntent.parkAdd -> {
                httpRequest(apiService.parkAdd(toBody(it.item)),HttpType.ADD)
            }

            ParkIntent.dict -> {
                httpRequest(apiService.dict())
            }

            is ParkIntent.parkDetail -> {
                httpRequest(apiService.parkDetail(it.pid),HttpType.DETAIL)
            }
            is ParkIntent.parkUpdate -> {
                httpRequest(apiService.parkUpdate(it.pid,toBody(it.item)),HttpType.UPDATE)
            }

            is ParkIntent.parkDelete -> {
                httpRequest(apiService.parkDelete(it.pid),HttpType.DELETE)
            }

            is ParkIntent.parkArea -> {
                httpRequest(apiService.parkArea(it.areaId),HttpType.DEFAULT)
            }
            is ParkIntent.parkCarNo -> {
                httpRequest(apiService.parkCarNo(it.carNo),HttpType.DEFAULT)
            }
            is ParkIntent.parkStatus -> {
                httpRequest(apiService.parkStatus(it.status),HttpType.DEFAULT)
            }
        }
    }
}